package com.itholmes.config;

import org.apache.zookeeper.ZooKeeper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContext;

@Component
public class ZookeeperConfig implements ApplicationRunner {

    @Autowired
    ServletContext servletContext;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("准备...");
        Watcher01 watcher01 = new Watcher01();
        ZooKeeper zk = new ZooKeeper("150.158.199.52:2181", 3000,watcher01);
        watcher01.zk = zk;
        servletContext.setAttribute("zookeeper",zk);
        System.out.println("连接..");
    }
}
